<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/24
 * Time: 14:49
 */

namespace Common\Model;


use Think\Model;

class WorkArrangeModel extends Model
{
    protected $tableName = 'work_arrange';

    protected $auto = array(
        array('send_time','time_format', self::MODEL_INSERT, 'function', NOW_TIME),
        array('state', 1),
    );

    public function update($data = null){
        $data = $this->token(false)->create($data);
        if (empty($data)){
            return false;
        }

        if (empty($data['work_arrange_id'])){
            $id = $this->add();
            if (!$id){
                $this->error = '新增工作安排出错';
                return false;
            }
            $data['work_arrange_id'] = $id;
        }else{
            $status = $this->save();
            if (false === $status){
                $this->error = '更新工作安排出错';
                return false;
            }
        }
        return $data;
    }

}